<?php

/**
 * Class UploadsController
 */
class UploadsController extends AppController {

	/**
	 * Model
	 *
	 * @type array
	 */
	public $uses = ['Upload'];

	/**
	 * Component
	 *
	 * @type array
	 */
	public $components = ['Paginator'];

	/**
	 * Helper
	 *
	 * @type array
	 */
	public $helpers = ['Form', 'Paginator'];

	/**
	 * Initialization
	 */
	public function beforeFilter() {
		parent::beforeFilter();
	}

	/**
	 * Upload index
	 */
	public function index() {
		$this->Paginator->settings = [
			'Product' => [
				'paramType' => 'querystring',
				'limit' => PHP_INT_MAX,
				'order' => [
					'Product.created' => 'desc'
				],
			]
		];
		$this->set('uploads', $this->Paginator->paginate());
		$this->set('topTitle', '文件上传');
	}

	/**
	 * Add upload
	 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Upload->create();
			if ($this->Upload->save($this->request->data)) {
				$this->Session->setFlash(__('New file uploaded'));
				return $this->redirect('/uploads/index');
			}
			$this->Session->setFlash(__('Could not upload file'));
		}
		$this->set('topTitle', '添加文件');
	}

	/**
	 * Edit upload
	 */
	public function edit() {
	}

	/**
	 * Delete upload
	 */
	public function delete() {
	}

	/**
	 * Destructor
	 */
	public function __destruct() {
	}
}